package org.example.mybatisdemo.mapper;

import org.apache.ibatis.annotations.*;
import org.example.mybatisdemo.model.UserInfo;

@Mapper
public interface UserInfoMapper2 {
    @Select("select * from user_info where id= #{id}")
    UserInfo selectById(Integer id);

    @Select("SELECT * from user_info where id=${id}")
    UserInfo selectById2(Integer id);

    @Select("select * from user_info where username=#{name}")
    //Mybatis会自动加上单引号
    UserInfo selectByName(String name);

    @Select("select * from user_info where username='${name}'")
    //Mybatis必须手动加上单引号
    UserInfo selectByName2(String name);

    @Options(useGeneratedKeys = true,  keyProperty = "id")
    @Insert("insert into user_info (username,password,age) value (#{username},#{password},#{age})")
    Integer insertUser(UserInfo userInfo);

    @Delete("delete from user_info where id=#{id}")
    Integer deleteById(Integer id);

    @Update("update user_info set gender = #{gender}, delete_flag = #{deleteFlag}  where id = #{id}")
    Integer updateUser(UserInfo userInfo);
}
